
import 'package:flutter_getx/core/net/net.dart';
import 'package:flutter_getx/ui/main/main_routers.dart';
import 'package:flutter_getx/ui/user/model/login_info.dart';
import 'package:flutter_getx/utils/cache_utils.dart';
import 'package:get/get.dart';

import 'login_logic.dart';

class LoginApi {

  final _dio = Get.find<LoginLogic>().dio;

  void login(String name, String password) {
    _dio.asyncRequest<dynamic>(Method.post,
        url: api_login,
        params: {
          'name': name,
          'password': password,
        },
        isShow: true, onSuccess: (data) {
      LoginInfo loginInfo = LoginInfo.fromJson(data);
      CacheUtils.saveLoginInfo(loginInfo);
      Get.offAllNamed(homePage);
    });
  }

}
